<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="js/jquery-1.12.4.min.js"></script>
</head>
<body>
<script>
    function submitForm() {
        $.ajax({
            url:"test4_submit",
            type:"post",
            data:$("#form1").serialize(),
            dataType:"json",
            success:function(data) {
                if (data.code==0) {
                    alert("token:" + data.msg);
                    localStorage.setItem("token",data.msg);
                    location.replace("index");
                } else {
                    $("#msg").hide().show('fast').html(data.msg);
                }
            }
        });
        return false;
    }
</script>
<div id="msg"></div>
<form id="form1" method="post" action="test4_submit" onsubmit="return submitForm()">
    <div>用户名：<input type="text" name="username"></div>
    <div>密码：<input type="text" name="userpwd"></div>
    <input type="submit" value="登录">
</form>
</body>
</html>
